#include "ServerManager.h"

SessionType ServerManager::_SsessionIndex = 0;
std::mutex ServerManager::_SSessionMutex;

SessionType ServerManager::SGetSessionIndex()
{
	std::lock_guard<std::mutex> guard(_SSessionMutex);
	_SsessionIndex++;
	if (_SsessionIndex == INVALID_SESSION_ID)
	{
		_SsessionIndex++;
	}
	return _SsessionIndex;
}

ServerManager::ServerManager()
{
}


bool ServerManager::InitServerManager()
{
	bool bret = false;
	_messageQueue = std::make_shared<MessageQueueManager>();
	_sockMInst = std::make_shared<SocketManagerPair>();
	_webMInst = std::make_shared<WebManagerPair>();
	_procMInst = std::make_shared<ProcManager>();
	_messageQueue->InitMessageQueueManager(_procMInst);
	bret = _sockMInst->InitSockManager("127.0.0.1",10086, _messageQueue);
	bret = _webMInst->InitWebManagerPair("127.0.0.1",10087, _messageQueue);
	_procMInst->InitProcManager(_webMInst.get(), std::thread::hardware_concurrency());
	return bret;
}

void ServerManager::StartServerManager()
{
	_sockMInst->StartSockManager();
	_webMInst->StartWebManagerPair();
	_procMInst->StartProcManager();
}

ServerManager::~ServerManager()
{
}
